package com.weitu.worklicense.service.impl;

import com.weitu.worklicense.entity.WorkLicenseApply;
import com.weitu.worklicense.entity.WorkLicenseApplyCriteria;
import com.weitu.worklicense.mapper.WorkLicenseApplyMapper;
import com.weitu.worklicense.service.WorkLicenseApplyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class WorkLicenseApplyServiceImpl implements WorkLicenseApplyService {
    private final WorkLicenseApplyMapper workLicenseApplyMapper;

    private static final Logger logger = LoggerFactory.getLogger(WorkLicenseApplyServiceImpl.class);

    @Autowired
    public WorkLicenseApplyServiceImpl(WorkLicenseApplyMapper workLicenseApplyMapper) {
        this.workLicenseApplyMapper = workLicenseApplyMapper;
    }

    @Override
    public int countByCriteria(WorkLicenseApplyCriteria example) {
        int count = this.workLicenseApplyMapper.countByCriteria(example);
        logger.debug("count: {}", count);
        return count;
    }

    @Override
    public WorkLicenseApply selectByPrimaryKey(String id) {
        return this.workLicenseApplyMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<WorkLicenseApply> selectByCriteria(WorkLicenseApplyCriteria example) {
        return this.workLicenseApplyMapper.selectByCriteria(example);
    }

    @Override
    @Transactional
    public int deleteByPrimaryKey(String id) {
        return this.workLicenseApplyMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public int updateByPrimaryKeySelective(WorkLicenseApply record) {
        return this.workLicenseApplyMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(WorkLicenseApply record) {
        return this.workLicenseApplyMapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional
    public int updateByCriteriaSelective(WorkLicenseApply record, WorkLicenseApplyCriteria example) {
        return this.workLicenseApplyMapper.updateByCriteriaSelective(record, example);
    }

    @Override
    @Transactional
    public int insertSelective(WorkLicenseApply record) {
        return this.workLicenseApplyMapper.insertSelective(record);
    }

    @Override
    public int countByNotAudited() {
        WorkLicenseApplyCriteria example = new WorkLicenseApplyCriteria();
        example.createCriteria()
                .andDelStateEqualTo(0)
                .andAuditStateEqualTo(0);
        return this.workLicenseApplyMapper.countByCriteria(example);
    }

    @Override
    public int countByNotHandled() {
        WorkLicenseApplyCriteria example = new WorkLicenseApplyCriteria();
        example.createCriteria()
                .andDelStateEqualTo(0)
                .andAuditStateEqualTo(7);
        return this.workLicenseApplyMapper.countByCriteria(example);
    }

    @Override
    public List<Map> countByWorkType() {
        return this.workLicenseApplyMapper.countByWorkType();
    }
}